package com.maddox.relax.permission

import androidx.fragment.app.FragmentActivity

/**
 * 请求权限的封装
 */
object PermissionX {

    private const val TAG = "LucencyFragment"

    fun request(
        activity: FragmentActivity,
        vararg permissions: String,
        callback: PermissionOnCallback
    ) {
        val fragmentManager = activity.supportFragmentManager
        val existedFragment = fragmentManager.findFragmentByTag(TAG)
        val fragment = if (existedFragment != null) {
            existedFragment as LucencyFragment
        } else {
            val lucencyFragment = LucencyFragment()
            fragmentManager.beginTransaction().add(lucencyFragment, TAG).commitNow()
            lucencyFragment

        }
        //调用权限  *permissions表示将一个数组转换成可变长度参数传递进去
        fragment.requestNow(callback,*permissions)

    }
}